package pers.test.votemanage.service.impl;

import lombok.Builder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import pers.test.votemanage.dao.UserMapper;
import pers.test.votemanage.domain.User;
import pers.test.votemanage.exception.CommException;
import pers.test.votemanage.service.UserService;

@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserMapper userMapper;

    @Override
    public void register(User user) {
        User user1 = userMapper.queryUserById(user.getPhone());
        if(user1 != null){
            throw new CommException("9999","该用户ID已经注册");
        }else{
           User user2 = User.builder().id(user.getId()).phone(user.getPhone()).
                    flag(user.getFlag()).name(user.getName()).build();
           userMapper.insert(user2);
        }
    }
}
